<?php
	check_login();
	$a = getAction();
	
	switch($a) {
		case 'index':
			$sql="select  *  from ".table('huifu')." where 1= 1 " ;
            $sql2="select  count(*)  from ".table('huifu')."  where 1= 1 ";
            $url="admin.php?m=huifu";
                        
            $title=trim($_GET['title']);
            if($title) {
            	$w.=" and content = '$title' ";
                $url.="&title={$title}";
            }
                        
			$openid=trim($_GET['openid']);
            if($openid) {
            	$w.=" and openid = '$openid' ";
                $url.="&openid={$openid}";
			}
                        
			$starttime=$_GET['starttime'] = $_GET['starttime1'];
            $endtime=$_GET['endtime'] = $_GET['endtime1'];
            if($starttime && $endtime) {
            	$url.="&starttime=$starttime&endtime=$endtime";
                $w.=" AND createtime>'$starttime' AND createtime<'$endtime' ";
			}
                        
            $sql.=$w;
            $sql2.=$w;
                        
            $sql.=" order by  id desc ";

            $rscount=$db->getOne($sql2);
            $pagesize=100;
            $page=max(1,intval($_GET['page']));
            $start=($page-1)*$pagesize;
            $pagelist=multipage($rscount,$pagesize,$page,$url);	
            $sql.=" limit $start,$pagesize";
            
            $smarty->assign("pagelist",$pagelist);

            $res2=$db->query($sql);
                        
            $menu = $db->getRow("select * from ".table('wxmenu')." WHERE 1= 1 ");
                        
            while($rs2 = $db->fetch_array($res2)) {
            	if(trim($rs2["msgtype"]) === "event" && substr($rs2["content"], 0, 5) === "CLICK") {
                	$rs2["contentkey"] = "自定义菜单：" .  getMenuName($menu, substr($rs2["content"], 5));
                }
                $rs2["username"] = $db->getOne("select nickname from " . table("user") . " where openid = '" . $rs2["fromuser"] . "'");
                
                $huifu[] = $rs2;
            }

			$smarty->assign("rscount",$rscount);//统计订单总数
            $smarty->assign("huifu",$huifu);
			$smarty->display("huifu.html");
			break;
		case 'del':
			$id=intval($_GET['id']);
			$db->query("DELETE FROM ".table('huifu')." WHERE id='$id' and 1= 1 ");
			break;
	}

	function getMenuName($menu, $key) {
		if (trim($menu["menu1key"]) == $key) {
			return $menu["menu1name"];
		} else if (trim($menu["menu1submenu1key"]) == $key) {
			return $menu["menu1submenu1name"];
		} else if (trim($menu["menu1submenu2key"]) == $key) {
			return $menu["menu1submenu2name"];
		} else if (trim($menu["menu1submenu3key"]) == $key) {
			return $menu["menu1submenu3name"];
		} else if (trim($menu["menu1submenu4key"]) == $key) {
			return $menu["menu1submenu4name"];
		} else if (trim($menu["menu1submenu5key"]) == $key) {
			return $menu["menu1submenu5name"];
		} else if (trim($menu["menu2key"]) == $key) {
			return $menu["menu2name"];
		} else if (trim($menu["menu2submenu1key"]) == $key) {
			return $menu["menu2submenu1name"];
		} else if (trim($menu["menu2submenu2key"]) == $key) {
			return $menu["menu2submenu2name"];
		} else if (trim($menu["menu2submenu3key"]) == $key) {
			return $menu["menu2submenu3name"];
		} else if (trim($menu["menu2submenu4key"]) == $key) {
			return $menu["menu2submenu4name"];
		} else if (trim($menu["menu2submenu5key"]) == $key) {
			return $menu["menu2submenu5name"];
		} else if (trim($menu["menu3key"]) == $key) {
			return $menu["menu3name"];
		} else if (trim($menu["menu3submenu1key"]) == $key) {
			return $menu["menu3submenu1name"];
		} else if (trim($menu["menu3submenu2key"]) == $key) {
			return $menu["menu3submenu2name"];
		} else if (trim($menu["menu3submenu3key"]) == $key) {
			return $menu["menu3submenu3name"];
		} else if (trim($menu["menu3submenu4key"]) == $key) {
			return $menu["menu3submenu4name"];
		} else if (trim($menu["menu3submenu5key"]) == $key) {
			return $menu["menu3submenu5name"];
		}
	}
?>